package com.c.ctgproject.ui.sell.parts

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.c.ctgproject.base.BaseViewModel
import com.c.ctgproject.http.ApiMethods
import com.c.ctgproject.utils.*

/**
 *作者:LiBW
 *创建日期: 2020/9/8
 *描述: 销售扫码进入页面 ViewModel
 */
class SellerScanViewModel : BaseViewModel() {
    private val mCarDetail = MutableLiveData<String>()
    val carDetail: LiveData<String> get() = mCarDetail

    private val mPreserveValue = MutableLiveData<String>()
    val preserveValue: LiveData<String> get() = mPreserveValue


    fun getCarDetail(carCode: String) {
        launch({
            mCarDetail.value = ApiMethods.getApiService().carInfo(userToken, carCode).awaitSync()
        }, {
            mError.value = it.message.toString()
        })
    }

    //有无销售价值 0- 无 1 - 有
    fun preserveValue(carCode: String, value: Int) {
        launch({
            mPreserveValue.value = ApiMethods.getApiService()
                .preserveValue(userToken, handlerBody("carCode" to carCode, "doSellValue" to value)).awaitSync()
        }, {
            mError.value = it.message.toString()
        })
    }
}